package edu.zut.cs.software.perfect.manage.service.impl;

import java.util.List;
import java.util.Optional;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.stereotype.Service;

import edu.zut.cs.software.perfect.base.service.impl.GenericTreeManagerImpl;
import edu.zut.cs.software.perfect.course.domain.CourseInformation;
import edu.zut.cs.software.perfect.manage.dao.AdministratorDao;
import edu.zut.cs.software.perfect.manage.domain.Administrator;
import edu.zut.cs.software.perfect.manage.service.AdministratorManager;
import edu.zut.cs.software.perfect.process.domain.CourseProcess;

/**
 * @ClassName adminManagerImpl
 * @Description TODO
 * @Author wst
 * @Date 2020年3月20日 下午1:19:49
 * @Version 1.0
 */
@Service(value="adminManager")
@Transactional
public class AdministratorManagerImpl extends GenericTreeManagerImpl<Administrator, Long> implements AdministratorManager {

	
	AdministratorDao adminDao;
	/**
	 * echo
	 */
	@Override
	public Administrator echo(Administrator message) {
		// TODO Auto-generated method stub
		String name="wst";
		String serial_number="rj181";
		message.setName(name);
		message.setSerial_number(serial_number);
		return message;

	}

	/**
	 * 
	 * @param admindao
	 */
	@Autowired
	public void setAdminDao(AdministratorDao adminDao) {
		this.adminDao = adminDao;
		this.treeDao=adminDao;
		this.dao=this.adminDao;
	}

	/**
	 * add admin
	 */
	@Override
	public Administrator add_a() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * delete admin
	 */
	@Override
	public Administrator delete_a() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * change admin message
	 */
	@Override
	public Administrator change_a() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * find admin
	 */
	@Override
	public Administrator find_a() {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public List<Administrator> findAll() {
		return (List<Administrator>) this.dao.findAll();
	}
	
	@Override
	public Administrator getAdministratorById(Long id) {
		
		Administrator administrator=new Administrator();
		
		administrator.setId(id);
		administrator.setName(adminDao.findById(id).get().getName());
		administrator.setSerial_number(adminDao.findById(id).get().getSerial_number());
		 
		 return administrator;
		
	}

	@Override
	public Boolean deleteById(Long Id) {
		// TODO Auto-generated method stub
		Optional<Administrator> administrator = this.dao.findById(Id);
		if(administrator.equals(Optional.empty())) {
			return false;
		} else {
			this.dao.delete(administrator.get());
			return true;
		}
	}
	
	public Optional<Administrator> findBycourseId(Long courseId) {
		Optional<Administrator> result = this.dao.findById(courseId);
		return result;
	}

}
